package com.itboye.sunsunhome.www.aq;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.itboye.base.BaseActivity;
import com.itboye.sunsunhome.www.aq.base.MyApplication;

public class UpdateDeviceActivity extends BaseActivity {
	MyApplication mApp;
	private EditText mEditTextName;
	private Button btn_seav;
	private ImageView updateback;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.update_device_name);
		mApp = (MyApplication) getApplication();
		// if (mApp.mEditDeviceInfo == null) {
		// this.finish();
		// }
		mEditTextName = (EditText) findViewById(R.id.edit_device_editText1);
		btn_seav = (Button) findViewById(R.id.btn_seav);
		mEditTextName.setText(mApp.mEditDeviceInfo.mDeviceName);
		updateback = (ImageView) findViewById(R.id.updateback);
		updateback.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		btn_seav.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onSend();
			}
		});
	}

	public void onSend() {
		OnToast("修改成功!", MyApplication.context);
		mApp.mEditDeviceInfo.mDeviceName = mEditTextName.getText().toString();
		mApp.addDevice(mApp.mEditDeviceInfo);
		this.finish();
	}

	/** 
     * 展示一个特定颜色的Toast 
     * 
     * @param message 
     */  
    protected void OnToast(String message,Context context) {  
        View toastRoot = LayoutInflater.from(context).inflate(R.layout.toast, null);  
        Toast toast = new Toast(context);  
        toast.setView(toastRoot);  
        TextView tv = (TextView) toastRoot.findViewById(R.id.toast_notice);  
        tv.setText(message);  
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();  
    }
}
